<template>
	<a-modal v-bind="options" v-on="events" class="enter-details">
		<a-form ref="enterForm" layout="vertical" :model="formData" :rules="enterpriseRules(formData)">
			<blockquote class="d-module-title">
				<strong>企业信息</strong>
			</blockquote>
			<a-row :gutter="16">
				<a-col :span="8">
					<a-form-item label="企业名称：" name="enterPriseName">
						<a-input v-model:value="formData.enterPriseName" placeholder="请输入企业名称" :maxlength="50" />
					</a-form-item>
				</a-col>

				<a-col :span="8">
					<a-form-item label="统一社会信用代码：" name="societyCode">
						<a-input
							v-model:value="formData.societyCode"
							placeholder="请输入统一社会信用代码"
							:maxlength="18"
							:disabled="!!props.id" />
					</a-form-item>
				</a-col>

				<a-col :span="8">
					<a-form-item label="企业法人：" name="enterPriseLegal">
						<a-input v-model:value="formData.enterPriseLegal" placeholder="请输入企业法人" :maxlength="20" />
					</a-form-item>
				</a-col>

				<a-col :span="8">
					<a-form-item label="企业电话：" name="enterPrisePhone">
						<a-input v-model:value="formData.enterPrisePhone" placeholder="请输入企业电话" :maxlength="20" />
					</a-form-item>
				</a-col>

				<a-col :span="16">
					<a-form-item label="企业地址：" name="enterPriseAddress">
						<a-input v-model:value="formData.enterPriseAddress" placeholder="请输入企业地址" :maxlength="100" />
					</a-form-item>
				</a-col>
			</a-row>
			<a-form-item class="table-form-item">
				<template #label>
					<strong class="d-module-title">联系人信息</strong>
				</template>
				<vxe-table size="mini" :data="formData.contacts" border="inner" align="center" max-height="200">
					<vxe-column min-width="200" title="姓名">
						<template #header="{column}">
							<span v-color="{color: 'danger'}">*</span>
							{{ column.title }}
						</template>
						<template #default="{row, rowIndex}">
							<a-form-item
								:name="['contacts', rowIndex, 'linkmanName']"
								:rules="[{required: true, message: '请输入联系人姓名'}]"
								has-feedback>
								<template #help />
								<a-input v-model:value="row.linkmanName" placeholder="请输入联系人姓名" :maxlength="10" />
							</a-form-item>
						</template>
					</vxe-column>
					<vxe-column width="150" title="性别">
						<template #default="{row}">
							<a-radio-group v-model:value="row.gender" name="radioGroup">
								<a-radio :value="1">男</a-radio>
								<a-radio :value="2">女</a-radio>
							</a-radio-group>
						</template>
					</vxe-column>
					<vxe-column min-width="200" title="手机号">
						<template #header="{column}">
							<span v-color="{color: 'danger'}">*</span>
							{{ column.title }}
						</template>
						<template #default="{row, rowIndex}">
							<a-form-item :name="['contacts', rowIndex, 'linkmanPhone']" :rules="phoneRules(row)" has-feedback>
								<template #help />
								<a-input v-model:value="row.linkmanPhone" placeholder="请输入联系人电话" :maxlength="11" />
							</a-form-item>
						</template>
					</vxe-column>
					<vxe-column min-width="150" title="职务">
						<template #default="{row}">
							<a-input v-model:value="row.linkmanPost" placeholder="请输入职务" :maxlength="10"></a-input>
						</template>
					</vxe-column>
					<vxe-column min-width="100" title="首选联系人">
						<template #default="{row}">
							<a-radio :checked="Boolean(row.isFirstChoice)" @change="changeHandler(row)"></a-radio>
						</template>
					</vxe-column>
					<vxe-column width="100" title="操作">
						<template #default="{row, rowIndex}">
							<a
								v-if="formData.contacts.length > 1"
								v-color="{color: 'danger'}"
								@click="onClickToRemoveRow(formData.contacts, rowIndex, 'contact')">
								<svg-icon icon-class="trash" />
							</a>
						</template>
					</vxe-column>
				</vxe-table>
				<a-button type="link" block @click="addContact">
					<plus-outlined />
					继续添加
				</a-button>
			</a-form-item>

			<a-form-item name="teamworks" v-if="props.type === 'storage'">
				<template #label>
					<a-space>
						<strong class="d-module-title">合作信息</strong>
						<small v-color="{color: 'secondary'}">
							点击"+"按钮添加，"x"按钮删除
							<span v-color="{color: 'red'}">（若要删除请按合作周期由远到近规则依次删除）</span>
						</small>
					</a-space>
				</template>
				<a-tabs
					v-model:activeKey="activeTeamworkIndex"
					type="editable-card"
					size="small"
					@edit="onTeamworkTabEdit"
					class="teamwork-edit-tab">
					<a-tab-pane
						v-for="(teamwork, i) in formData.teamworks"
						:key="i"
						:closable="formData.teamworks.length > 1 && i === formData.teamworks.length - 1">
						<template #tab>{{ teamwork.beginTime }}至{{ teamwork.endTime }}</template>

						<a-row :gutter="16">
							<a-col :span="16">
								<a-form-item label="合作周期：" required>
									<a-input-group compact class="display-flex">
										<a-range-picker
											:value="[teamwork.beginTime, teamwork.endTime]"
											:value-format="DATE_FORMAT.DATE"
											:allow-empty="[true, true]"
											:disabled-date="current => teamworkDisabledDate(current, i)"
											@change="dates => onTeamworkDateChange(teamwork, dates)"
											style="flex: 1" />
										<a-form-item-rest>
											<a-radio-group
												class="month-quick-radio-group"
												v-model:value="teamwork.leasePeriod"
												button-style="solid"
												@change="onTeamworkDateChange(teamwork)">
												<a-radio-button :value="1">1年</a-radio-button>
												<a-radio-button :value="2">2年</a-radio-button>
												<a-radio-button :value="3">3年</a-radio-button>
												<a-radio-button :value="5">5年</a-radio-button>
											</a-radio-group>
										</a-form-item-rest>
									</a-input-group>
								</a-form-item>
							</a-col>
							<a-col :span="8">
								<a-form-item label="协议附件：">
									<a-button type="primary" ghost block @click="showFileUpload(teamwork)">
										<template v-if="teamwork.imgIdList?.length">
											<check-outlined />
										</template>
										<plus-outlined v-else />
									</a-button>
								</a-form-item>
							</a-col>
						</a-row>

						<a-form-item
							label="协议优惠方案："
							:name="['teamworks', i, 'discounts']"
							class="table-form-item"
							style="margin-bottom: 0">
							<a-form-item-rest>
								<vxe-table
									:data="teamwork.discounts"
									size="mini"
									border="inner"
									max-height="300"
									empty-text="请添加优惠协议方案">
									<vxe-column min-width="150" title="优惠方案名称">
										<template #header="{column}">
											<span v-color="{color: 'danger'}">*</span>
											{{ column.title }}
										</template>
										<template #default="{row, rowIndex}">
											<a-input v-model:value="row.discountName" placeholder="请输入协议名称" :maxlength="20" />
										</template>
									</vxe-column>
									<vxe-column min-width="240" title="优惠有效期">
										<template #header="{column}">
											<span v-color="{color: 'danger'}">*</span>
											{{ column.title }}
										</template>
										<template #default="{row, rowIndex}">
											<a-range-picker
												:value="[row.beginTime, row.endTime]"
												:value-format="DATE_FORMAT.DATE"
												:disabled-date="current => discountDisabledDate(current, teamwork)"
												@change="dates => onDateChangeDetails(row, dates)" />
										</template>
									</vxe-column>
									<vxe-column width="100" title="优惠类型">
										<template #header="{column}">
											<span v-color="{color: 'danger'}">*</span>
											{{ column.title }}
										</template>
										<template #default="{row}">
											<a-select v-model:value="row.type" :options="typeOptions" placeholder="请选择" />
										</template>
									</vxe-column>
									<vxe-column width="120" title="优惠方式">
										<template #header="{column}">
											<span v-color="{color: 'danger'}">*</span>
											{{ column.title }}
										</template>
										<template #default="{row, rowIndex}">
											<a-select
												v-model:value="row.discountType"
												:options="discountTypeOptions"
												@change="e => changeDiscountType(teamwork, row, e)"
												placeholder="请选择" />
										</template>
									</vxe-column>
									<vxe-column width="140" title="优惠折扣">
										<template #header="{column}">
											<span v-color="{color: 'danger'}">*</span>
											{{ column.title }}
										</template>
										<template #default="{row, rowIndex}">
											<a-input-number
												v-if="row.type === 1"
												v-model:value="row.discountScale"
												addon-after="%"
												:precision="0"
												:min="0"
												:max="100"
												:controls="false"
												placeholder="折扣比例" />
											<a-input-number
												v-else
												v-model:value="row.discountScale"
												addon-before="-"
												addon-after="元"
												:precision="2"
												:min="0"
												:max="9999"
												:controls="false"
												placeholder="优惠金额" />
											<!-- </a-form-item> -->
										</template>
									</vxe-column>
									<vxe-column width="100" title="是否可叠加">
										<template #default="{row, rowIndex}">
											<a-checkbox v-model:checked="row.stackable">可叠加</a-checkbox>
										</template>
									</vxe-column>
									<vxe-column min-width="150" title="优惠范围">
										<template #header="{column}">
											<span v-color="{color: 'danger'}">*</span>
											{{ column.title }}
										</template>
										<template #default="{row, rowIndex}">
											<a-select
												v-model:value="row.feeSubjectIds"
												mode="tags"
												show-search
												maxTagCount="responsive"
												option-filter-prop="name"
												placeholder="请选择费用科目">
												<template v-for="item in feeSubjectsList" :key="item.id">
													<a-select-option v-if="row.discountType === 1" :value="item.id">
														{{ item.name }}
													</a-select-option>
													<a-select-option v-else-if="item.tag === DIC_TAG_MAP.HOUSE_RENT" :value="item.id">
														{{ item.name }}
													</a-select-option>
												</template>
											</a-select>
										</template>
									</vxe-column>
									<vxe-column width="60" title="操作" align="center">
										<template #default="{row, rowIndex}">
											<a v-color="{color: 'danger'}" @click.stop="onClickToRemoveRow(teamwork.discounts, rowIndex)">
												<svg-icon icon-class="trash" />
											</a>
										</template>
									</vxe-column>
								</vxe-table>
								<a-button type="link" block @click="addDiscountAgree(teamwork)">
									<plus-outlined />
									继续添加
								</a-button>
							</a-form-item-rest>
						</a-form-item>
					</a-tab-pane>
				</a-tabs>
			</a-form-item>

			<blockquote class="d-module-title">
				<strong>录入信息</strong>
			</blockquote>

			<a-row :gutter="16">
				<a-col :span="12">
					<a-form-item label="录入人：" name="employeeId">
						<!-- 合并录入人和维护人 -->
						<dept-emp-select v-model:emp-id="formData.employeeId" disabled placeholder="请选择录入人" />
					</a-form-item>
				</a-col>

				<!-- <a-col :span="12">
					<a-form-item label="维护人" name="preservePerSionId">
						<dept-emp-select v-model:emp-id="formData.preservePerSionId" placeholder="请选择维护人" />
					</a-form-item>
				</a-col> -->
			</a-row>
		</a-form>

		<template #footer>
			<a-button :loading="loading" @click="events.cancel()">取消</a-button>
			<a-button type="primary" :loading="loading" @click="submit()">确认</a-button>
		</template>

		<!-- 附件上传 -->
		<file-upload-dialog
			v-model:visible="visibles.attachment"
			v-model:files="formData.teamworks[activeTeamworkIndex].imgIdList"
			:biz-id="formData.teamworks[activeTeamworkIndex].id" />
		<!-- 回显 -->
	</a-modal>
</template>

<script setup lang="ts">
	import {createVNode, onMounted, reactive, ref, toRef, watch} from 'vue'
	import {useStore} from '@/store/index'
	import settingApi from 'yuxin-base/src/api/setting-api'
	import {message, Modal} from 'ant-design-vue'
	import {CheckOutlined, PlusOutlined, QuestionCircleOutlined} from '@ant-design/icons-vue'
	import {enterpriseDetails, enterpriseWarehousingFun, updateEnterpriseWarehousing} from '@/api/enterprise-library'
	import {DIC_LABEL_MAP, DIC_TAG_MAP} from 'yuxin-base/src/constant'
	import DATE_FORMAT, {nowDate} from 'yuxin-base/src/utils/date'
	import dayjs, {Dayjs} from 'dayjs'
	import {discountTypeOptions, typeOptions} from '@/interface/interface'
	import FileUploadDialog from '@/components/common/file-upload-dialog.vue'
	import {enterpriseRules} from '@/utils/formValidation'
	import XEUtils from 'xe-utils'
	import {Img} from 'yuxin-base/src/types'

	const store = useStore()

	const props = defineProps<{
		visible: boolean
		type: string
		id?: string
		status?: number | string
	}>()

	const options = reactive({
		width: 1200,
		title: '企业入库',
		maskClosable: false,
		centered: true,
		destroyOnClose: true,
		bodyStyle: {padding: '14px 14px 0', height: '80vh', overflow: 'auto'},
		visible: toRef(props, 'visible')
	})

	const emits = defineEmits(['update:visible', 'close'])

	const events = reactive({
		cancel() {
			enterForm.value.resetFields()
			formData.value.id = null
			activeTeamworkIndex.value = 0
			formData.value.contacts = [defaultContact()]
			formData.value.teamworks = [defaultTeamwork()]
			emits('update:visible', false)
		}
	})

	onMounted(() => {
		getDics()
	})
	const loading = ref(false)

	const enterForm = ref()

	const visibles = reactive({
		attachment: false,
		attId: '',
		updateAttachment: false
	})

	/**
	 * 协议优惠
	 */
	type Discount = {
		id?: string | null
		// 1折扣 2减免
		type: 1 | 2
		// 	协议名称
		discountName: string | null
		// 1每月折 2首月折 3尾月折
		discountType: 1 | 2 | 3
		// 	折扣比例
		discountScale: number | null
		// 有效期
		endTime: string | null
		beginTime: string | null
		// 优惠是否可叠加
		stackable: boolean
		// 优惠范围，费用科目ID集合
		feeSubjectIds: string[] | null
	}

	/**
	 * 企业合作周期
	 */
	type Teamwork = {
		id?: string | null
		leasePeriod: number
		// 合作周期开始时间
		beginTime: string | null
		// 合作周期结束时间
		endTime: string | null
		// 附件ID集合
		imgIdList: string[] | null
		// 协议优惠列表
		discounts: Discount[] | null
	}

	/**
	 * 企业联系人
	 */
	type Contact = {
		id?: string | null
		// 姓名
		linkmanName: string | null
		// 联系人性别【1-男,2-女】
		gender: 1 | 2 | null
		// 联系人电话
		linkmanPhone: string | null
		// 职务
		linkmanPost: string | null
		// 是否首选联系人 1首选 0不是首选
		isFirstChoice: 0 | 1 | number
	}

	type FormData = {
		id?: string | null
		// 企业名称
		enterPriseName: string | null
		// 社会统一代码
		societyCode: string | null
		// 企业法人
		enterPriseLegal: string | null
		// 企业电话
		enterPrisePhone: string | null
		// 企业地址
		enterPriseAddress: string | null
		// 维护人
		employeeId: null | string
		// 合作周期
		teamworks: Teamwork[]
		// 联系人
		contacts: Contact[]
		[key: string]: any
	}

	const defaultTeamwork = (): Teamwork => ({
		id: null,
		leasePeriod: 2,
		beginTime: nowDate(),
		endTime: dayjs().add(2, 'year').add(-1, 'day').format(DATE_FORMAT.DATE),
		imgIdList: [],
		discounts: []
	})

	const defaultContact = (): Contact => ({
		id: null,
		// 姓名
		linkmanName: null,
		gender: 1,
		linkmanPhone: null,
		// 职务
		linkmanPost: null,
		isFirstChoice: 1
	})

	const formData = ref<FormData>({
		id: null,
		employeeId: null,
		societyCode: null,
		enterPriseName: null,
		enterPriseLegal: null,
		enterPrisePhone: null,
		enterPriseAddress: null,
		teamworks: [defaultTeamwork()],
		//联系人信息
		contacts: [defaultContact()]
	})

	// 费用类型
	const feeSubjectsList = ref<any[]>([])

	const phoneRules: any = (contact: Contact) => [
		{
			required: true,
			validator: async (_rule: any, value: string) => {
				if (!value) {
					return Promise.reject('请输入联系人手机号')
				} else if (!/^1[3-9]\d{9}$/.test(value)) {
					return Promise.reject('手机号格式不正确')
				} else {
					const phones = formData.value.contacts.filter(o => o != contact).map(o => o.linkmanPhone)

					if (phones.includes(value)) {
						return Promise.reject(`联系人【${contact.linkmanName}】的手机号【${value}】已存在，请更换`)
					}
				}

				return Promise.resolve()
			}
		}
	]

	const showFileUpload = (teamwork: any) => {
		visibles.attachment = true
		visibles.attId = teamwork.id
	}

	const getDetail = () => {
		if (props.id) {
			enterpriseDetails(props.id).then(({data}) => {
				if (XEUtils.isEmpty(data.teamworks)) {
					data.teamworks = [defaultTeamwork()]
				}

				data.teamworks = data.teamworks as []
				formData.value = data
			})
		}
	}

	watch(
		() => props.visible,
		(newVal: boolean) => {
			if (newVal) {
				formData.value.employeeId = store.currentUser?.empId
				options.title = '企业入库'
				if (props.id) {
					options.title = '编辑企业入库'
					getDetail()
				}
			} else {
				visibles.attachment = false
			}
		}
	)

	const submit = () => {
		enterForm.value
			.validateFields()
			.then(() => {
				loading.value = true

				const params = {
					enterprise: {
						id: formData.value.id,
						societyCode: formData.value.societyCode,
						enterPriseName: formData.value.enterPriseName,
						enterPriseLegal: formData.value.enterPriseLegal,
						enterPrisePhone: formData.value.enterPrisePhone,
						enterPriseAddress: formData.value.enterPriseAddress
					},
					contacts: formData.value.contacts,
					teamworks: formData.value.teamworks.map((o: any) => {
						o.imgIdList = (o.imgIdList || []).map(o => o.id)
						return o
					})
				}

				const action = props.id ? updateEnterpriseWarehousing : enterpriseWarehousingFun

				action(params)
					.then(() => {
						loading.value = false
						success()
					})
					.catch(() => (loading.value = false))
			})
			.catch(({errorFields}) => {
				loading.value = false
				message.error(errorFields.flatMap(o => o.errors).join('、'))
			})
	}

	const success = () => {
		events.cancel()
		emits('close')
		activeTeamworkIndex.value = 0
	}

	const addTeamwork = () => {
		// 结束日期减去当前日期 >30不能添加

		if (dayjs(formData.value.teamworks[activeTeamworkIndex.value]?.endTime).diff(nowDate(), 'day') > 30) {
			return Modal.info({
				title: '系统提示',
				content: '距离本段合作周期结束超过30天，如合同周期变更，建议直接修改合作周期'
			})
		}

		const teamworks = formData.value.teamworks

		teamworks.push({
			id: null,
			leasePeriod: 2,
			beginTime: dayjs(teamworks[teamworks.length - 1].endTime)
				.add(1, 'day')
				.format(DATE_FORMAT.DATE),
			endTime: dayjs(teamworks[teamworks.length - 1].endTime)
				.add(2, 'year')
				.add(-1, 'day')
				.format(DATE_FORMAT.DATE),
			imgIdList: [],
			discounts: []
		})

		activeTeamworkIndex.value = teamworks.length - 1
	}

	const getDics = () => {
		settingApi.getDicListByLabel(DIC_LABEL_MAP['FEESUBJECT']).then(({data = []}) => {
			// 只需要房屋租金和押金
			feeSubjectsList.value = data
				.flatMap(o => o.metaList)
				.filter(o => [DIC_TAG_MAP.HOUSE_DEPOSIT, DIC_TAG_MAP.HOUSE_RENT].includes(o.tag))
		})
	}

	// 当前正在编辑的合作周期
	const activeTeamworkIndex = ref(0)

	const onTeamworkTabEdit = (i, action) => {
		if (action === 'add') {
			addTeamwork()
		} else {
			onClickToRemoveRow(formData.value.teamworks, i, 'teamwork')
		}
	}

	// 合作周期禁用日期
	const teamworkDisabledDate = (current: Dayjs, index: number) => {
		const teamworks = formData.value.teamworks
		// 上一合作周期、下一合作周期
		const prev = teamworks[index - 1],
			next = teamworks[index + 1]

		return (
			(prev && dayjs(prev.endTime).add(1, 'day').isAfter(current, 'day')) ||
			(next && dayjs(next.beginTime).subtract(1, 'day').isBefore(current, 'day'))
		)
	}

	// 合作周期变更
	const onTeamworkDateChange = (teamwork: Teamwork, dates: string[]) => {
		// 汇总所有合作周期为二维数组，判断是否有重叠
		const times = formData.value.teamworks.map(o => [o.beginTime, o.endTime])

		// dates为空时快捷选择
		if (dates) {
			// 给当前合作周期赋值结束日期
			times[activeTeamworkIndex.value] = dates
		} else {
			// 根据快捷选择计算当前周期结束日期
			const endTime = dayjs(teamwork.beginTime).add(teamwork.leasePeriod, 'year').subtract(1, 'day')

			// 给当前合作周期赋值结束日期
			times[activeTeamworkIndex.value][1] = endTime.format(DATE_FORMAT.DATE)
			dates = times[activeTeamworkIndex.value] as []
		}

		// 按开始日期排序
		const orderTimes = XEUtils.orderBy(times, item => item[0])

		let preTimes: any = null

		for (let times of orderTimes) {
			if (preTimes !== null) {
				// 上一周期结束日期与下一周日开始日期比较，晚于下一周期开始日期则合作周期交差重叠，提示重新选择
				if (dayjs(preTimes[1]).isAfter(times[0])) {
					return message.warning('合同周期不可与其它周期重叠，请重新选择')
				}
			}
			preTimes = times
		}

		// 汇总协议优惠周期，判断是否超出合作周期
		const beginTimes = teamwork.discounts?.map(o => o.beginTime) || []
		const endTimes = teamwork.discounts?.map(o => o.endTime) || []

		// 合同周期开始日期不能晚于协议优惠开始日期
		if (beginTimes.some(time => dayjs(dates[0]).isAfter(time, 'day'))) {
			return message.warning('合同周期开始日期不能晚于协议优惠开始日期')
		}

		// 合同周期开始日期不能早于协议优惠开始日期
		if (endTimes.some(time => dayjs(dates[1]).isBefore(time, 'day'))) {
			return message.warning('合同周期开始日期不能早于协议优惠开始日期')
		}

		teamwork.beginTime = times[activeTeamworkIndex.value][0]
		teamwork.endTime = times[activeTeamworkIndex.value][1]
	}

	// 优惠周期时间的限制
	const discountDisabledDate = (current: Dayjs, teamwork: Teamwork) => {
		return current.isBefore(teamwork.beginTime, 'day') || current.isAfter(teamwork.endTime, 'day')
	}

	const onDateChangeDetails = (discount: Discount, dates: string[]) => {
		if (dates) {
			discount.beginTime = dates[0]
			discount.endTime = dates[1]
		}
	}

	const onClickToRemoveRow = (array: any[], index: number, type: string) => {
		Modal.confirm({
			title: '系统提示',
			content: '删除后无法恢复，确定删除？',
			centered: true,
			icon: createVNode(QuestionCircleOutlined),
			onOk() {
				const item: any[] = array.splice(index, 1)
				if (type === 'contact') {
					if (item[0].isFirstChoice) {
						array[0].isFirstChoice = 1
					}
				} else if (type === 'teamwork') {
					activeTeamworkIndex.value = index === 0 ? 0 : index - 1
				}
			}
		})
	}

	/**
	 * 添加优惠协议
	 * @param teamwork 当前合作周期
	 */
	const addDiscountAgree = (teamwork: any) => {
		// console.log('addAgree-index===', index)
		teamwork.discounts.push({
			// 1折扣 2减免
			type: 1,
			// 1每月折 2首月折 3尾月折
			discountType: 1,
			// 	折扣比例
			discountScale: null,
			// 	协议名称
			discountName: null,
			// 有效期
			endTime: teamwork.endTime,
			beginTime: teamwork.beginTime,
			// 优惠方式
			feeSubjectIds: [feeSubjectsList.value[0]?.id],
			// 优惠是否可叠加
			stackable: null
		})
	}
	// 添加联系人
	const addContact = () => {
		formData.value.contacts.push({...defaultContact(), isFirstChoice: 0})
	}

	const changeHandler = (data: Contact) => {
		formData.value.contacts.forEach((e: Contact) => (e.isFirstChoice = Number(e === data)))
	}

	/** 变更优惠类型 */
	const changeDiscountType = (teamwork: any, row: any, e: any) => {
		// 租金id
		let id = feeSubjectsList.value.filter(o => [DIC_TAG_MAP.HOUSE_RENT].includes(o.tag))[0].id

		// console.log('🚀 ~ file: enterprise-warehousing.vue:788 ~ changeDiscountType ~ e:', e, feeSubjectsList.value[0]?.id, id)

		//  当选择不是每月择的时候 范围只需要租金
		if (e !== 1) {
			teamwork.discounts.forEach((item: any) => {
				if (item === row) {
					if (item.feeSubjectIds.includes(id)) {
						item.feeSubjectIds = [id]
					} else {
						item.feeSubjectIds = []
					}
				}
			})
		}
	}
</script>

<style lang="less" scoped>
	.table-form-item {
		:deep {
			> .ant-form-item-control {
				border: 1px solid @border-color-light;
			}
		}
	}

	.teamwork-edit-tab {
		:deep {
			.ant-tabs-nav {
				margin-bottom: 0;
			}

			.ant-tabs-content-holder {
				padding: 12px;
				border: 1px solid @border-color-light;
				border-top: none;

				.vxe-body--column {
					padding: 6px 0;

					.vxe-cell {
						padding: 0 6px;

						.ant-select {
							width: 100%;
						}
					}
				}
			}
		}
	}
</style>
